(function(window){
	var Subject_lookintoCtrl = {
		data:{},
		init: function(data){
			this.bindEven();
			$("#tkjd").width($(".tk_home").width());
			var tkjd_w=$("#tkjd").width();
			var l=$(".tmitem").length;
			var w=tkjd_w/l;
			Subject_lookintoCtrl.data.tmitem_w=w;
			$(".tmitem").width(w);
			$(".tmitem:last").width(0);
			$(".tmitem").parent().css("padding-left",w/2+"px");
			$("#dqts").css("left",(w/2+4)+"px");
			
		 
        },
		post_answer:function(){
			var data_id=$(this).attr("data-id");
		    $("#questions_answer_"+data_id).show();
			var answer_remark=$('[data-id="all_questions_'+data_id+'"]').find(".answer_remark")
			answer_remark.show();
				var anwser=$("#hideQuestionanswer_"+data_id).val();
			var post_anwser="";
			$('[data-id="all_questions_'+data_id+'"]').find("dd .checked").each(function(i,v){
				 post_anwser+=$(v).attr("key");
			});
			if(post_anwser==anwser){
				var answer="right";
				var remark='<span class="glyphicon glyphicon-ok-circle"></span>';
				$.post("/User/del_collect_questions",{qid:data_id});
			}else{
				var answer="wrong";
				var remark='<span class="glyphicon glyphicon-remove-circle"></span>';
			}
			$('[data-id="all_questions_'+data_id+'"]').find("dd").unbind(hiApp.device.click);
			answer_remark.html(remark);
			$(this).hide();	
			var datatid=data_id;
			var _this=$('[datatid="'+datatid+'"]');
			var img=$("#tk_jd_bg_"+answer).clone();
			_this.find(".tk_jd_bg").html(img);
			_this.prev().find(".jiange").addClass("bar_"+answer);
			var tk_jd_bg_img=_this.find(".tk_jd_bg img");
			$(tk_jd_bg_img).css("display","inherit");
			$(tk_jd_bg_img).animate({top:"0px"});
			var index=$(".tmitem").index(_this);
			Subject_lookintoCtrl.animate_to(index);
			
		},
		tmitem:function(){
			var p=$(this).parent();
			var datatid=p.attr("datatid");
			var index=$(".tmitem a").index($(this));
			Subject_lookintoCtrl.animate_to(index);
			$(".all_questions").hide();
			$("[data-id='all_questions_"+datatid+"']").show();
			
		},
		animate_to:function(index){
			var tmitem_w=Subject_lookintoCtrl.data.tmitem_w;
			var left=tmitem_w*index+(tmitem_w/2+4);
			$("#dqts").animate({left:left+"px"});
		},
		questions_next:function(){
			var _this=$(".all_questions:visible");
			var l= _this.next(".all_questions").length;
			if(l==0){
				var count_wrong_all=$("#count_wrong_all").val();
				var nextUrl=$("#nextUrl").val();
				
				if(Number(count_wrong_all)>0){
					hiApp.confirm("已做到最后一道题了，您还有剩下"+count_wrong_all+"道错题，是否继续消灭错题？",function(){
						window.location.href=nextUrl;
					});
				}else{
					dialog("恭喜，您已经消灭完所有错题");	
				}
				
			}else{
				_this.hide();
				_this.next(".all_questions").show();
			}
		},
		bindEven: function(){
            var bindings = [{
                element:'.sumbit_answer',
                event: hiApp.device.click,
                handler: this.post_answer
            },
			{
                element:'.tmitem a',
                event: hiApp.device.click,
                handler: this.tmitem
            },
			{
                element:'.questions_next',
                event: hiApp.device.click,
                handler: this.questions_next
            }
			];
            bindEvents(bindings);
        },
		 
		
    };
		
	window.BoxEdu_Subject_lookintoCtrl = Subject_lookintoCtrl;
						
})(window);